package net.hvacapp.cmvrfforandroid.ui.project;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.mirror.android.common.util.StringUtils;

import net.hvacapp.cmvrfforandroid.R;
import net.hvacapp.cmvrfforandroid.adapter.BaseAdapterHelper;
import net.hvacapp.cmvrfforandroid.adapter.QuickAdapter;
import net.hvacapp.cmvrfforandroid.constant.Constant;
import net.hvacapp.cmvrfforandroid.http.BasicHttpClient;
import net.hvacapp.cmvrfforandroid.http.HttpCallbackHandle;
import net.hvacapp.cmvrfforandroid.http.HttpConstant;
import net.hvacapp.cmvrfforandroid.manager.AccountManager;
import net.hvacapp.cmvrfforandroid.manager.ProjectManager;
import net.hvacapp.cmvrfforandroid.ui.BaseActivity;
import net.hvacapp.cmvrfforandroid.ui.MainTabBarActivity;
import net.hvacapp.cmvrfforandroid.ui.project.model.GetIndoorEquipDataResp;
import net.hvacapp.cmvrfforandroid.ui.project.model.GetProductDataResp;
import net.hvacapp.cmvrfforandroid.ui.project.model.GetQrjhqDataResp;
import net.hvacapp.cmvrfforandroid.ui.project.model.GuidData;
import net.hvacapp.cmvrfforandroid.ui.project.model.ProjectInfoData;
import net.hvacapp.cmvrfforandroid.ui.project.model.QrjhqData;
import net.hvacapp.cmvrfforandroid.ui.project.model.RoomData;
import net.hvacapp.cmvrfforandroid.ui.project.view.DeviceItemView;
import net.hvacapp.cmvrfforandroid.utils.AnnotationUtil;
import net.hvacapp.cmvrfforandroid.utils.NumberUtil;
import net.hvacapp.cmvrfforandroid.widget.CellSeperateLineView;
import net.hvacapp.cmvrfforandroid.widget.IOSAlertView;
import net.hvacapp.cmvrfforandroid.widget.ItemSelectionView;
import net.hvacapp.cmvrfforandroid.widget.ProjectActionView;
import net.hvacapp.cmvrfforandroid.widget.UserSelectionView;

import org.androidannotations.annotations.AfterViews;
import org.androidannotations.annotations.EActivity;
import org.androidannotations.annotations.ViewById;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@EActivity(R.layout.activity_project_step6)
public class ProjectStep6Activity extends BaseActivity {

    private final int Select_QRJHQ = 1;
    private final int Select_QRJHQ_Xl = 2;

    @ViewById(R.id.action_view)
    ProjectActionView mActionView;


    private Dialog mProgressDlg;

    @ViewById(R.id.lv_templete)
    ListView mTempleteLv;

    private QuickAdapter<QrjhqData> mQuickAdapter;

    private ArrayList<QrjhqData> mQrjhqData;

    private QrjhqData mCurrentQRJHQ;

    private List<GuidData> mCandiData; //可选型式



    /**
     * 页面加载完后执行
     */
    @AfterViews
    @Override
    protected void viewDidLoad() {
        super.viewDidLoad();
        initViews();
        initEvent();
    }

    /***
     * 初始化视图
     */
    private void initViews() {
        mActionView.setActionInfo(ProjectManager.getInstance().getTotal(), ProjectManager.getInstance().getCurrent());
    }

    /**
     * 初始化
     */
    @Override
    public void initBoot() {
        mQrjhqData = new ArrayList<>();
        mCandiData = null;

        setupToolbar(R.string.title_for_project, "全热交换器配置", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(AnnotationUtil.get(MainTabBarActivity.class));
            }
        });

//        int ids[] = {R.id.action_new_qrjhq};
//        int icons[] = {R.drawable.new_project};
//        setupToolbarMenuItem(ids, icons, new String[]{"新建"}, null);
        setButton1Info("新建", new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                addOneProjectQRJHQInfo();
            }
        });


        if (mQuickAdapter == null){
            mQuickAdapter = new QuickAdapter<QrjhqData>(context, R.layout.qrjhq_config_cell_item) {
                @Override
                protected void convert(final BaseAdapterHelper helper, final QrjhqData item) {
                    LinearLayout QRJHQInfoLl = helper.getView(R.id.ll_qrjhq_info);
                    QRJHQInfoLl.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //控制显示隐藏
                            item.setClosed(!item.isClosed());
                            if (item.isClosed()) {
                                helper.setImageResource(R.id.iv_selected_mark, R.drawable.arrow_down);
                                helper.setVisible(R.id.ll_qrjhq_content, false);
                            } else {
                                helper.setImageResource(R.id.iv_selected_mark, R.drawable.arrow_up);
                                helper.setVisible(R.id.ll_qrjhq_content, true);
                            }
                        }
                    });

                    helper.setText(R.id.tv_title, item.getName());
                    helper.setText(R.id.tv_description, "总风量：" + NumberUtil.formateDouble(item.getVentVol()) + "立方米/h");

                    TextView deleteTv = helper.getView(R.id.tv_delete);
                    deleteTv.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //删除

                            Map<String, Object> param = new HashMap<>();
                            param.put("qiid", item.getGuidId());

                            BasicHttpClient.httpDeleteAsync(HttpConstant.HTTP_DELETE_PROJECT_ONE_QRJHQ, AccountManager.getInstance().getToken(), param, new HttpCallbackHandle<GetQrjhqDataResp>() {
                                @Override
                                public void onSuccess(GetQrjhqDataResp obj) {
                                    //需要重新拉取所有的系统数据
                                    mQuickAdapter.remove(item);
                                    mQrjhqData.remove(item);
                                }

                                @Override
                                public void onFailure(String response) {
                                    showMessage("删除全热交换器系统失败！");
                                }
                            });
                        }
                    });

                    //房间面积
                    final EditText areaCet = helper.getView(R.id.cet_area);

                    areaCet.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            try {
                                Double area = Double.valueOf(areaCet.getText().toString());
                                if (area > 0) {
                                    //修改项目信息
                                    item.setRoomArea(area);
                                    //换气量
                                    double amout = item.getRoomArea() * item.getFloorHeight() *item.getVentRate();
                                    helper.setText(R.id.tv_amount, NumberUtil.formateDouble(amout));
                                    modifyProjectQRJHQInfo(item);
                                }
                            } catch (NumberFormatException e) {
                                showMessage("请输入合法的格式");
                            }
                        }

                        @Override
                        public void afterTextChanged(Editable s) {

                        }
                    });
                    if (item.getRoomArea() > 0) {
                        areaCet.setText(""+NumberUtil.formateDouble(item.getRoomArea()));
                    }

                    //房间高度
                    final EditText heightCet = helper.getView(R.id.cet_height);
                    heightCet.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            try {
                                Double height = Double.valueOf(heightCet.getText().toString());
                                if (height > 0) {
                                    //修改项目信息
                                    item.setFloorHeight(height);
                                    //换气量
                                    double amout = item.getRoomArea() * item.getFloorHeight() *item.getVentRate();
                                    helper.setText(R.id.tv_amount, NumberUtil.formateDouble(amout));
                                    modifyProjectQRJHQInfo(item);
                                }
                            } catch (NumberFormatException e) {
                                showMessage("请输入合法的格式");
                            }
                        }

                        @Override
                        public void afterTextChanged(Editable s) {

                        }
                    });
                    if (item.getFloorHeight() > 0) {
                        heightCet.setText(""+NumberUtil.formateDouble(item.getFloorHeight()));
                    }

                    //换气次数
                    final EditText timesCet = helper.getView(R.id.cet_times);
                    timesCet.addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

                        }

                        @Override
                        public void onTextChanged(CharSequence s, int start, int before, int count) {
                            try {
                                Double times = Double.valueOf(timesCet.getText().toString());
                                if (times > 0) {
                                    //修改项目信息
                                    item.setVentRate(times);
                                    //换气量
                                    double amout = item.getRoomArea() * item.getFloorHeight() *item.getVentRate();
                                    helper.setText(R.id.tv_amount, NumberUtil.formateDouble(amout));
                                    modifyProjectQRJHQInfo(item);
                                }
                            } catch (NumberFormatException e) {
                                showMessage("请输入合法的格式");
                            }
                        }

                        @Override
                        public void afterTextChanged(Editable s) {

                        }
                    });
                    if (item.getVentRate() > 0) {
                        timesCet.setText(""+NumberUtil.formateDouble(item.getVentRate()));
                    }

                    //选择换气次数
                    TextView selectTv = helper.getView(R.id.tv_select_amount);
                    selectTv.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //给定的换气量
                            String[] items = ProjectStep6Activity.this.getResources().getStringArray(
                                    R.array.ventArray);
                            new AlertDialog.Builder(ProjectStep6Activity.this)
                                    .setTitle("选择房间类型")
                                    .setItems(items, new DialogInterface.OnClickListener() {

                                        public void onClick(DialogInterface dialog,
                                                            int which) {
                                            switch (which) {
                                                case 0:
                                                    timesCet.setText("0.5");
                                                    break;
                                                case 1:
                                                    timesCet.setText("2.7");
                                                    break;
                                                case 2:
                                                    timesCet.setText("1.8");
                                                    break;
                                                case 3:
                                                    timesCet.setText("4.5");
                                                    break;
                                                case 4:
                                                    timesCet.setText("4.5");
                                                    break;
                                                case 5:
                                                    timesCet.setText("0.9");
                                                    break;
                                                case 6:
                                                    timesCet.setText("0.8");
                                                    break;
                                                case 7:
                                                    timesCet.setText("1.9");
                                                    break;
                                                case 8:
                                                    timesCet.setText("2.2");
                                                    break;
                                                case 9:
                                                    timesCet.setText("3.3");
                                                    break;
                                                case 10:
                                                    timesCet.setText("5.0");
                                                    break;
                                                default:
                                                    break;
                                            }
                                            //修改项目信息
                                            Double times = Double.valueOf(timesCet.getText().toString());
                                            if (times > 0) {
                                                //修改项目信息
                                                item.setVentRate(times);
                                                //换气量
                                                double amout = item.getRoomArea() * item.getFloorHeight() *item.getVentRate();
                                                helper.setText(R.id.tv_amount, NumberUtil.formateDouble(amout));
                                                modifyProjectQRJHQInfo(item);
                                            }
                                        }
                                    })
                                    .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                        @Override
                                        public void onClick(DialogInterface dialog, int which) {

                                        }
                                    })
                                    .show();
                        }
                    });

                    //换气量
                    double amout = item.getRoomArea() * item.getFloorHeight() *item.getVentRate();
                    helper.setText(R.id.tv_amount, NumberUtil.formateDouble(amout));

                    //选择全热交换器
                    UserSelectionView selectionView = helper.getView(R.id.sel_qrjhq);
                    selectionView.setTitleString("全热交换器");
                    selectionView.setInfoString("请选择");

                    selectionView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //选择全热交换器设备
                            mCurrentQRJHQ = item;
                            Intent intent = new Intent(ProjectStep6Activity.this, AnnotationUtil.get(SelectDeviceXlActivity.class));
                            Bundle bundle = new Bundle();
                            bundle.putBoolean("multiple", false);
                            bundle.putString("tag", ProjectInfoData.MACHINE_TAG_FOR_QRJHQ);
                            intent.putExtras(bundle);
                            startActivityForResult(intent, Select_QRJHQ);
                        }
                    });

                    //自动选型
                    TextView autoTv = helper.getView(R.id.tv_qrjhq);
                    autoTv.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //自动选型点击
                            mCurrentQRJHQ = item;
                            if (mCandiData != null && mCandiData.size() == 1) {
                                //只有一个系列时，直接开始自动选型
                                ProjectManager.getInstance().setProjectDefaultSeries(ProjectInfoData.MACHINE_TAG_FOR_QRJHQ, mCandiData.get(0).getGuidId());
                                getQRJHQDefaultDevice(mCurrentQRJHQ);
                                return;
                            }
                            Intent intent = new Intent(ProjectStep6Activity.this, AnnotationUtil.get(SelectXlActivity.class));
                            Bundle bundle = new Bundle();
                            bundle.putBoolean("multiple", false);
                            bundle.putString("tag", ProjectInfoData.MACHINE_TAG_FOR_QRJHQ);
                            intent.putExtras(bundle);
                            startActivityForResult(intent, Select_QRJHQ_Xl);
                        }
                    });

                    //添加设备
                    LinearLayout QRJHQContent = helper.getView(R.id.ll_device);
                    QRJHQContent.removeAllViews();

                    CellSeperateLineView line = new CellSeperateLineView(ProjectStep6Activity.this);
                    QRJHQContent.addView(line);

                    final DeviceItemView itemView = new DeviceItemView(ProjectStep6Activity.this);

                    if (StringUtils.isEmpty(item.getQrjhqId()) || StringUtils.isEquals(item.getQrjhqId(), Constant.EMPTY_DEVICE_ID)) {
                        itemView.setDeviceString("请选择");
                    }
                    else {
                        itemView.setDeviceString(item.getXh());
                    }
                    itemView.setCount(item.getCount());
                    itemView.deleteBtnDismiss();

                    itemView.setOnMinusClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            int count = itemView.getCount();
                            if (count > 1) {
                                count--;
                            } else {
                                return;
                            }
                            item.setCount(count);
                            itemView.setCount(count);
                            //修改数量
                            modifyProjectQRJHQInfo(item);

                        }
                    });
                    itemView.setOnAddClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            int count = itemView.getCount();
                            count++;
                            item.setCount(count);
                            itemView.setCount(count);
                            //修改数量
                            modifyProjectQRJHQInfo(item);
                        }
                    });
                    QRJHQContent.addView(itemView);

                }
            };
        }

        mTempleteLv.setAdapter(mQuickAdapter);
    }

    /**
     * toolbar上的按钮点击事件
     * @param item
     * @return
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.action_new_qrjhq:
                addOneProjectQRJHQInfo();
                break;
            default:
                break;
        }
        return super.onOptionsItemSelected(item);
    }


    /**
     * 初始化数据
     */
    @Override
    public void initData(Intent intent) {
        loadProjectQrjhqInfo();
        loadProjectSelectedSeries();
    }



    /**
     * 页面名称
     */
    @Override
    public String getName() {
        return "";
    }

    private void initEvent() {
        mActionView.setLeftOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //上一步
                ProjectManager.getInstance().goLastStep();
                finish();
            }
        });

        mActionView.setRightOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //下一步
                goNextStep();
            }
        });

    }

    private void goNextStep() {
        ProjectManager.getInstance().goNextStep();
        if (ProjectManager.getInstance().kqnrsjPageEnabled()) {
            //跳转到空气能热水机页面
            startActivity(AnnotationUtil.get(ProjectStep7Activity.class));
        }
        else {
            //跳转到设备报价页面
            startActivity(AnnotationUtil.get(ProjectStep8Activity.class));
        }
    }


    /**
     *  获取项目中全热交换器的配置
     */
    private void loadProjectQrjhqInfo() {
        Map<String, Object> param = new HashMap<>();
        param.put("pid", ProjectManager.getInstance().getProjectData().getGuidId());

        mProgressDlg = createProgressBarDialog(this, "数据加载中...");
        mProgressDlg.show();

        BasicHttpClient.httpGetAsync(HttpConstant.HTTP_GET_PROJECT_QRJHQ, AccountManager.getInstance().getToken(), param, new HttpCallbackHandle<GetQrjhqDataResp>() {
            @Override
            public void onSuccess(GetQrjhqDataResp obj) {
                // 成功
                mProgressDlg.dismiss();
                mQrjhqData.clear();
                mQuickAdapter.clear();
                mQrjhqData.addAll(obj.getGetQrjhqInfosResult());
                mQuickAdapter.addAll(obj.getGetQrjhqInfosResult());
            }

            @Override
            public void onFailure(String response) {
                mProgressDlg.dismiss();
                showMessage("获取全热交换器信息失败，请重试！");
            }
        });

    }

    /**
     *  获取项目中选择了的系列
     */
    private void loadProjectSelectedSeries() {
        Map<String, Object> param = new HashMap<>();
        param.put("pid", ProjectManager.getInstance().getProjectData().getGuidId());
        param.put("tag", ProjectInfoData.MACHINE_TAG_FOR_QRJHQ);

        BasicHttpClient.httpGetAsync(HttpConstant.HTTP_GET_PROJECT_PRODUCT_SERIES, AccountManager.getInstance().getToken(), param, new HttpCallbackHandle<GetProductDataResp>() {
            @Override
            public void onSuccess(GetProductDataResp obj) {
                // 成功
                if (obj.getGetCandidateXlsResult() != null && obj.getGetCandidateXlsResult().size() > 0) {
                    mCandiData = obj.getGetCandidateXlsResult();
                }
            }

            @Override
            public void onFailure(String response) {
//                showMessage("获取系列失败，请重试！");
            }
        });
    }


    /**
     * 修改全热交换器的房间信息
     * @param data
     */
    private void modifyProjectQRJHQInfo(QrjhqData data) {
        Map<String, Object> param = new HashMap<>();
        param.put("qrjhqInfoData", data);

        BasicHttpClient.httpPostAsync(HttpConstant.HTTP_POST_PROJECT_ONE_QRJHQ, AccountManager.getInstance().getToken(), param, new HttpCallbackHandle<GetQrjhqDataResp>() {
            @Override
            public void onSuccess(GetQrjhqDataResp obj) {
                //需要重新拉取所有的系统数据
//                loadProjectQrjhqInfo();
            }

            @Override
            public void onFailure(String response) {
                showMessage("修改全热交换器系统失败！");
            }
        });

    }

    /**
     * 修改全热交换器的房间信息
     * @param data
     */
    private void modifyAndLoadProjectQRJHQInfo(QrjhqData data) {
        Map<String, Object> param = new HashMap<>();
        param.put("qrjhqInfoData", data);

        BasicHttpClient.httpPostAsync(HttpConstant.HTTP_POST_PROJECT_ONE_QRJHQ, AccountManager.getInstance().getToken(), param, new HttpCallbackHandle<GetQrjhqDataResp>() {
            @Override
            public void onSuccess(GetQrjhqDataResp obj) {
                //需要重新拉取所有的系统数据
                loadProjectQrjhqInfo();
            }

            @Override
            public void onFailure(String response) {
                showMessage("修改全热交换器系统失败！");
            }
        });

    }

    /**
     *  添加一套全热交换器系统
     */
    private void addOneProjectQRJHQInfo() {
        String url = HttpConstant.HTTP_PUT_PROJECT_ONE_QRJHQ
                + "?tk=" + AccountManager.getInstance().getToken()
                + "&pid=" + ProjectManager.getInstance().getProjectData().getGuidId();

        final QrjhqData data = new QrjhqData();
        ArrayList<String> rm = new ArrayList<>();

        data.setGuidId(null);
        int count = mQrjhqData.size() + 1;
        data.setName("系统" + count);
        data.setQrjhqId(Constant.EMPTY_DEVICE_ID);
        data.setXh(null);

        mProgressDlg = createProgressBarDialog(this, "添加新配置中...");
        mProgressDlg.show();


        Map<String, Object> param = new HashMap<>();
        param.put("qrjhqInfoData", data);

        BasicHttpClient.httpPutAsync(url, param, new HttpCallbackHandle<GetQrjhqDataResp>() {
            @Override
            public void onSuccess(GetQrjhqDataResp obj) {
                // 成功
                mProgressDlg.dismiss();
                data.setGuidId(obj.getCreateQrjhqInfoResult());
                mQrjhqData.add(data);
                mQuickAdapter.add(data);
            }

            @Override
            public void onFailure(String response) {
                mProgressDlg.dismiss();
                showMessage("添加全热交换器失败，请重试！");
            }
        });
    }

    /***
     * 对轻型商用空调自动选型
     */
    private void getQRJHQDefaultDevice(final QrjhqData data) {
        if (StringUtils.isEmpty(ProjectManager.getInstance().getProjectDefaultSeries(ProjectInfoData.MACHINE_TAG_FOR_QRJHQ))) {
            IOSAlertView.showAlertView(ProjectStep6Activity.this, "提示", "没有获取到默认型式，自动选型失败！", "确认", null);
            return;
        }

        mProgressDlg = createProgressBarDialog(ProjectStep6Activity.this, "自动选型中...");
        mProgressDlg.show();
        Map<String, Object> param = new HashMap<>();
        param.put("qiid", data.getGuidId());
        param.put("xlid", ProjectManager.getInstance().getProjectDefaultSeries(ProjectInfoData.MACHINE_TAG_FOR_QRJHQ));

        BasicHttpClient.httpGetAsync(HttpConstant.HTTP_GET_QRJHQ_DEFAULT_DEVICE, AccountManager.getInstance().getToken(), param, new HttpCallbackHandle<GetQrjhqDataResp>() {
            @Override
            public void onSuccess(GetQrjhqDataResp obj) {
                // 成功
                mProgressDlg.dismiss();
                if (obj.getAutoQrjhqEquipResult() != null) {
                    mQuickAdapter.remove(data);
                    mQrjhqData.remove(data);
                    mQuickAdapter.add(obj.getAutoQrjhqEquipResult());
                    mQrjhqData.add(obj.getAutoQrjhqEquipResult());
                } else {
                    IOSAlertView.showAlertView(ProjectStep6Activity.this, "提示", "超出该系列能力范围，请选择其他合适型式。", "确认", null);
                }
            }

            @Override
            public void onFailure(String response) {
                mProgressDlg.dismiss();
                IOSAlertView.showAlertView(ProjectStep6Activity.this, "提示", "超出该系列能力范围，请选择其他合适型式。", "确认", null);
            }
        });
    }



    /**
     * 回调
     * @param requestCode
     * @param resultCode
     * @param data
     */
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != this.RESULT_OK) {
            return;
        }
        if (requestCode == Select_QRJHQ) {
            if (data != null) {
                ArrayList<GuidData> arrayData = data.getParcelableArrayListExtra("device");
                if (arrayData != null && arrayData.size() > 0) {
                    GuidData selectData = arrayData.get(0);
                    mCurrentQRJHQ.setQrjhqId(selectData.getGuidId());
                    mCurrentQRJHQ.setXh(selectData.getName());
                    modifyAndLoadProjectQRJHQInfo(mCurrentQRJHQ);
                }
            }
        }
        else if (requestCode == Select_QRJHQ_Xl) {
            if (data != null) {
                List<GuidData> xl = data.getParcelableArrayListExtra("device");
                if (xl != null && xl.size() > 0) {
                    //开始自动选型
                    ProjectManager.getInstance().setProjectDefaultSeries(ProjectInfoData.MACHINE_TAG_FOR_QRJHQ, xl.get(0).getGuidId());
                    getQRJHQDefaultDevice(mCurrentQRJHQ);
                }
            }
        }
    }

}
